package com.hll.api.controller;

import com.hll.api.config.web.RespMessage;
import com.hll.api.service.WallpaperApi;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 获取壁纸
 *
 * @author 何龙
 * @create 2019-06-03 15:19
 */
@RestController
@RequestMapping("/api/wallpaper")
public class WallpaperController {
    @Resource
    WallpaperApi api;


    /**
     * @api {get} /api/wallpaper/type 获取壁纸分类
     * @apiVersion 1.0.0
     * @apiName type
     * @apiGroup wallpaper
     * @apiSuccess {Number} status 状态码,0为接口访问成功
     * @apiSuccess {String} err 错误信息
     * @apiSuccess {Object[]} datas 成功时返回数组
     * @apiSuccess {String} datas.id 分类id
     * @apiSuccess {String} datas.name 分类名称
     * @apiSuccess {String} datas.create_time 创建时间
     * @apiSuccessExample {json} 成功示例：
     * {
     * "status": 0,
     * "err": null,
     * "datas": [
     * {
     * "create_time": "2015-12-08 13:50:44",
     * "name": "4K专区",
     * "id": "36",
     * "order_num": "110",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-10-29 17:49:27",
     * "name": "美女模特",
     * "id": "6",
     * "order_num": "100",
     * "tag": ""
     * },
     * {
     * "create_time": "2012-11-23 10:49:25",
     * "name": "爱情美图",
     * "id": "30",
     * "order_num": "99",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-11-02 16:33:34",
     * "name": "风景大片",
     * "id": "9",
     * "order_num": "98",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-12-15 18:47:03",
     * "name": "小清新",
     * "id": "15",
     * "order_num": "85",
     * "tag": ""
     * },
     * {
     * "create_time": "2012-07-27 17:17:42",
     * "name": "动漫卡通",
     * "id": "26",
     * "order_num": "84",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-11-02 17:38:58",
     * "name": "明星风尚",
     * "id": "11",
     * "order_num": "83",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-12-15 18:23:27",
     * "name": "萌宠动物",
     * "id": "14",
     * "order_num": "75",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-10-29 17:49:12",
     * "name": "游戏壁纸",
     * "id": "5",
     * "order_num": "74",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-12-13 18:59:40",
     * "name": "汽车天下",
     * "id": "12",
     * "order_num": "72",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-11-02 17:10:53",
     * "name": "炫酷时尚",
     * "id": "10",
     * "order_num": "70",
     * "tag": ""
     * },
     * {
     * "create_time": "2012-11-23 09:19:54",
     * "name": "月历壁纸",
     * "id": "29",
     * "order_num": "69",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-11-02 15:22:39",
     * "name": "影视剧照",
     * "id": "7",
     * "order_num": "68",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-12-14 18:47:32",
     * "name": "节日美图",
     * "id": "13",
     * "order_num": "67",
     * "tag": "节日 端午 中秋 元旦 圣诞 清明 情人 春节 新年 2012"
     * },
     * {
     * "create_time": "2012-05-29 15:10:04",
     * "name": "军事天地",
     * "id": "22",
     * "order_num": "14",
     * "tag": ""
     * },
     * {
     * "create_time": "2011-12-30 11:37:49",
     * "name": "劲爆体育",
     * "id": "16",
     * "order_num": "12",
     * "tag": ""
     * },
     * {
     * "create_time": "2012-03-28 23:52:39",
     * "name": "BABY秀",
     * "id": "18",
     * "order_num": "10",
     * "tag": ""
     * },
     * {
     * "create_time": "2014-09-25 18:35:57",
     * "name": "文字控",
     * "id": "35",
     * "order_num": "9",
     * "tag": ""
     * }
     * ]
     * }
     */
    @GetMapping("/type")
    public RespMessage getType() throws Exception {
        return RespMessage.success( api.getType(), null );
    }


    /**
     * @api {get} /api/wallpaper/image/list 壁纸列表
     * @apiVersion 1.0.0
     * @apiName image
     * @apiGroup wallpaper
     * @apiParam {String} key 接口秘钥
     * @apiParam {String} cid 壁纸分类id<br/>
     * 是壁纸分类接口中获取的分类id
     * @apiParam {Integer} [start] 页码
     * @apiParam {Integer} [count] 每页条数
     * @apiParamExample {string} 请求示例:
     * key=123456789&cid=26&start=1&count=1
     * @apiSuccess {Number} status 状态码,0为接口访问成功
     * @apiSuccess {String} err 错误信息
     * @apiSuccess {Object[]} datas 成功时返回数组
     * @apiSuccess {String} datas.total 壁纸总数
     * @apiSuccess {Object[]} datas.list 壁纸列表
     * @apiSuccess {String} datas.list.utag 标题
     * @apiSuccess {String} datas.list.update_time 更新时间
     * @apiSuccess {String} datas.list.url 图片链接
     * @apiSuccess {String} datas.list.url_mobile 图片链接
     * @apiSuccess {String} datas.list.url_thumb 图片链接
     * @apiSuccess {String} datas.list.img_1366_768 图片链接
     * @apiSuccess {String} datas.list.img_1024_768 图片链接
     * @apiSuccess {String} datas.list.img_1600_900 图片链接
     * @apiSuccess {String} datas.list.img_1280_1024 图片链接
     * @apiSuccess {String} datas.list.img_1440_900 图片链接
     * @apiSuccessExample {json} 成功示例：
     * {
     * "status": 0,
     * "err": null,
     * "datas": {
     * "total": 10000,
     * "list": [
     * {
     * "url_mobile": "http://p19.qhimg.com/t01030f651e9df4443d.jpg",
     * "img_1280_800": "http://p19.qhimg.com/bdm/1280_800_85/t01030f651e9df4443d.jpg",
     * "update_time": "2019-05-30 19:47:33",
     * "utag": "卡通人物 机械 人类",
     * "urlurl_thumb": "http://p19.qhimg.com/t01030f651e9df4443d.jpg",
     * "url_mid": "http://p19.qhimg.com/t01030f651e9df4443d.jpg",
     * "img_1366_768": "http://p19.qhimg.com/bdm/1366_768_85/t01030f651e9df4443d.jpg",
     * "img_1024_768": "http://p19.qhimg.com/bdm/1024_768_85/t01030f651e9df4443d.jpg",
     * "img_1600_900": "http://p19.qhimg.com/bdm/1600_900_85/t01030f651e9df4443d.jpg",
     * "img_1280_1024": "http://p19.qhimg.com/bdm/1280_1024_85/t01030f651e9df4443d.jpg",
     * "img_1440_900": "http://p19.qhimg.com/bdm/1440_900_85/t01030f651e9df4443d.jpg",
     * "url": "http://p19.qhimg.com/bdr/__85/t01030f651e9df4443d.jpg"
     * }
     * ]
     * }
     * }
     * @apiErrorExample {json} 返回错误示例:
     * {
     * "status": 2,
     * "err": "秘钥不能为空",
     * "datas": []
     * }
     */
    @GetMapping("/image/list")
    public RespMessage imageList(String key, String cid,
                                 @RequestParam(value = "start", defaultValue = "1") Integer start,
                                 @RequestParam(value = "count", defaultValue = "20") Integer count) throws Exception {
        if (key == null) {
            return RespMessage.error( "秘钥不能为空" );
        }
        if (cid == null) {
            return RespMessage.error( "cid不能为空" );
        }

        return RespMessage.success( api.getImageList( cid, start, count ), null );
    }

}
